﻿using JT808.Gateway.Client;
using JT808.Gateway.SimpleClient.Customs;
using JT808.Gateway.SimpleClient.Services;
using JT808.Gateway.WebApiClientTool;
using JT808.Protocol;
using JT808.Protocol.Extensions.JT1078;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Serilog;
namespace JT808.Gateway.SimpleClient
{
    class Program
    {
        static async Task Main(string[] args)
        {
            var serverHostBuilder = new HostBuilder()
                .ConfigureAppConfiguration((hostingContext, config) =>
                {
                    config.SetBasePath(AppDomain.CurrentDomain.BaseDirectory);
                    config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
                })
                .ConfigureServices((hostContext, services) =>
                {
                    services.AddSingleton<ILoggerFactory, LoggerFactory>();
                    services.AddJT808Configure()
                        .AddJT1078Configure()
                        .AddClient()
                        .Builder()
                        //可以注册一个或者可以自定义扩展
                        .AddWebApiClientTool(new Uri("http://127.0.0.1:828/"), "123456")
                        .AddWebApiClientTool<JT808HttpClientExt>(new Uri("http://127.0.0.1:828/"), "123456");
                    //services.AddHostedService<Up2011Service>();
                    //services.AddHostedService<Up2013Service>();
                    services.AddHostedService<Up2019Service>();

                    //services.AddHostedService<CallHttpClientJob>();
                    //services.AddHostedService<CallHttpClientJobExt>();
                })
                .UseSerilog((context, loggerConfiguration) =>
                {
                    loggerConfiguration.ReadFrom.Configuration(context.Configuration);
                });
            await serverHostBuilder.RunConsoleAsync();
        }
    }
}
